// pages/mine/otherOrderDetail/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      type:1,
      id:0,
      dataObj:{},
      isShowAlert:false,
      number:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      type:wx.getStorageSync("shop_type"),
      id:options.id
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData();
  },
 
  hideAlert(){
    this.setData({
      isShowAlert:false
    })
  },
  confirmOrder(e){
    let url = 'api/shopr/confirmOilOrder';
    console.log(e)
    let number = e.detail.value ?  e.detail.value.number :''; 
    app.post({
      url: url,
      data:{
        order_id:this.data.id,
        user_id:wx.getStorageSync('userId'),
        number:number
      },
      success:(e)=>{
        let res = e.data.data;
        if(res.type == 1){
          console.log(res)
          this.setData({
            isShowAlert:true,
            number:res.number
          })
          return
        }
        wx.showToast({
          title: '确认成功',
          icon:'none'
        })
        this.getData()
        this.hideAlert()
      }
    })
  },
  getData(){
    let url = 'api/shopr/oilOrderDetail';
    console.log(url)
    app.post({
      url: url,
      data:{
        order_id:this.data.id
      },
      success:(e)=>{
        let res = e.data.data;
        let other_price = res.original_price - res.price;
        res.other_price = other_price.toFixed(2);
        this.setData({
          dataObj:res
        });
      }
    });
  },
})